package server_logic;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;



public class DBconnector {

	private boolean isConnected=false;
	public static Connection conn;
	String schem;
	String dbUser;
	String dbPass;
	
	public DBconnector(String schem,String dbUser, String dbPass  ) {

		this.schem=schem;
		this.dbUser=dbUser;
		this.dbPass=dbPass;
		connectToDB();
		
		// TODO Auto-generated constructor stub
	}
	
	private void connectToDB(){
		
	
    //open a connection to the db 
    try
    {
    	Class.forName("com.mysql.jdbc.Driver").newInstance();
    } catch(Exception ext) {}
    
   try {
			conn = DriverManager.getConnection("jdbc:mysql://localhost/test","root","admin1");
			isConnected=true;
			System.out.println("SQL connection succed - sasha comp");
		} catch (SQLException e) {
				try {
					conn = DriverManager.getConnection("jdbc:mysql://localhost/"+schem,dbUser,dbPass);
					isConnected=true;
					System.out.println("SQL connection succed - to braude");
				}catch(SQLException ex){
					ex.printStackTrace();
				}
				
		}
   
	
	
	
	}
	
	
	

	public boolean isConnected() {
		return isConnected;
	}


}
